//
//  YRUNVC.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/3/7.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "YRUNVC.h"
#import "SDCycleScrollView.h"

#import "YRunHomeCell.h"

@interface YRUNVC ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>




@property (nonatomic,strong) UITableView *YRUNTableView;

@end

@implementation YRUNVC


- (UITableView *)YRUNTableView
{
    if (!_YRUNTableView) {
        _YRUNTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
        _YRUNTableView.showsVerticalScrollIndicator = NO;
        _YRUNTableView.delegate = self;
        _YRUNTableView.dataSource = self;
        _YRUNTableView.backgroundColor = k_TableBackColor;
        _YRUNTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _YRUNTableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.Nav.backgroundColor = kClearColor;
    
    [self.leftbutton setImage:IMAGE(@"back_circle_gry") forState:UIControlStateNormal];
    [self.rigltbutton setImage:IMAGE(@"clork") forState:UIControlStateNormal];
    [self.view addSubview:self.YRUNTableView];
    
    [self.view bringSubviewToFront:self.Nav];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;  //section == 0 ? 2:4;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    tableView.tableHeaderView = [self creatSDCycleScrollView:nil];

    return [self searchHeadView ];  //section == 0 ? [UIView new] :
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 58; //section == 0 ? 5.f:80.f;
    
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [self footView];//section == 0 ? nil :[self footBtn ];
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 58; //section == 0 ? 0.f :k_TabBarHeight;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 125+12;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
   static  NSString * cellIdentif = @"YRunHomeCell.h";
    
    YRunHomeCell *cell  = [tableView dequeueReusableCellWithIdentifier:cellIdentif];
    if (!cell) {
        cell = [[YRunHomeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentif];
    }
    return cell;
    
}


- (UIView *)searchHeadView {
    
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 58)];
    headView.backgroundColor = k_TableBackColor;
    
    UILabel * lefTitL = [ReduceCode creatLabelWithFrame:CGRectMake(12, 0, 80, 15) title:@"跑场名单" titleColor:UIColorFromRGB(0x333333) font:15 textAlignment:NSTextAlignmentLeft];
    lefTitL.centerY = headView.centerY;
    [headView addSubview:lefTitL];
    
    return headView;
}

- (UIView *)footView {
    
    UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 58)];
    
    for (int F = 0; F<2; F++) {
        
      UIButton * footBtn = [UIButton creatBtnWithFrame:CGRectMake(kScreenWidth/2*F, 0, kScreenWidth/2, 58) btnTitle:@"快速加入" btnTitleColor:kWhiteColor btnTitleFont:14 btnTagPrice:70+F btnSetImage:nil btnBackgroundColor:UIColorFromRGB(0xe8632b) isCorner:NO action:^(UIButton *button) {
          
          
        }];
        
        if (F == 1) {
            footBtn.backgroundColor = UIColorFromRGB(0x464b5e);
            [footBtn setTitle:@"创建房间" forState:UIControlStateNormal];
        }
        [footView addSubview:footBtn];
    }
    return footView;
    
}

- (SDCycleScrollView *)creatSDCycleScrollView:(NSArray *)SDCycleArr{
    
    SDCycleScrollView *cycleScrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 222)];
    [cycleScrollView setPlaceholderImage:IMAGE(@"bg")];
    
//    NSMutableArray * sdCyclUrl = [NSMutableArray array];
//    
//    for (int i = 0; i<SDCycleArr.count; i++) {
//        NSDictionary * tempDic = SDCycleArr[i];
//        [sdCyclUrl addObject:[tempDic valueForKey:@"img"]];
//    }
    cycleScrollView.backgroundColor = kRedColor;
//    cycleScrollView.localizationImageNamesGroup = @[@""];
    
    if (SDCycleArr.count == 1) {
        cycleScrollView.infiniteLoop = NO;
    }else{
        cycleScrollView.infiniteLoop = YES;
    }
    cycleScrollView .delegate = self;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    cycleScrollView.autoScrollTimeInterval = 3.5;
    cycleScrollView.currentPageDotColor = HOME_COLOR;
    cycleScrollView.pageDotColor = [UIColor grayColor];
    
    return cycleScrollView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
